<script lang="tsx" setup>
/**
 * 退款
 */
import {defineDialogSheetForm, DialogSheetForm} from "@/frame/view/layout/dialog-sheet-form/constructor.ts"
import {nextTick, ref} from "vue"
import {processRequest} from "@/frame/apis/request"
import {ElMessage} from "element-plus"

/**
 * 定义emit
 */
const emit = defineEmits<{
  (e: "confirm"): void
}>()

/**
 * 页面实例
 */
const dialogSheetFormModelRef = ref()
const form = defineDialogSheetForm<any>({
  title: "退款",
  width: 500,
  sheetForm: {
    labelWidth: "100px",
    els: [
      {
        label: "金额",
        eType: "el-input",
        prop: "amount",
        props: {
          placeholder: "金额",
          clearable: true
        }
      },
      {
        label: "附件",
        eType: "el-upload",
        prop: "file",
        props: {
          action: "/development/anqin/api/Upload",
          limit: 1
        }
      },
      {
        label: "备注",
        eType: "el-input",
        prop: "remark",
        props: {
          placeholder: "备注",
          clearable: true
        }
      }
    ]
  }
})

/**
 * 显示
 */
const show = (params: any) => {
  dialogSheetFormModelRef.value.addForm()
  nextTick(() => {
    dialogSheetFormModelRef.value.setFormData({
      id: params.id
    })
  })
}

/**
 * 提交
 */
const handleSubmit = async (data: any) => {
  await processRequest.post("/api/PayManages/Return", {
    ...data
  })
  ElMessage.success("退款成功")
  emit("confirm")
  dialogSheetFormModelRef.value.close()
}

/**
 * 暴露
 */
defineExpose({
  show
})
</script>

<template>
  <DialogSheetForm ref="dialogSheetFormModelRef" :dialogSheetFormModel="form" @submit="handleSubmit"/>
</template>

<style lang="scss" scoped>

</style>